<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="p" uri="/tld/custom.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Employee list</title>
		<link type="text/css" rel="stylesheet" href="view/styles/style.css" />
	</head>
	<body>
		<div id="main">
			<div id="header">
				<jsp:include page="tiles/header.jsp" />	
			</div>
			<div id="content">
			<a href="controller?command=main">Main</a>
				<p:paging currentPageNumber="${param.page}" pagesRange="11"
							 entriesPerPage="${sessionScope.entriesPerPage}" entriesNumber="${requestScope.employeesNumber}"
							  pageAction="controller?command=employeeList" changeEntriesAction="controller?command=changeEntriesPerPage"/>
				<table>
					<tr>
						<th class="nameHeader" colspan="2">Name</th>
						<th class="addressHeader" colspan="5">Employee address</th>
						<th class="employmentHeader" colspan="8">Employment</th>
					</tr>
					<tr>
						<th rowspan="2">Last name</th>
						<th rowspan="2">First name</th>
						<th rowspan="2">Country</th>
						<th rowspan="2">City</th>
						<th rowspan="2">Street</th>
						<th rowspan="2">House</th>
						<th rowspan="2">Suite</th>
						<th rowspan="2">Company</th>
						<th colspan="6">Office info</th>
						<th rowspan="2">Position</th>
					</tr>
					<tr>
						<th>Country</th>
						<th>City</th>
						<th>Street</th>
						<th>House</th>
						<th>Suite</th>
						<th>Count</th>
					</tr>
					<c:forEach items="${employees}" var="employee">
						<tr>
							<c:set value="${employee.employments.size() + 1}" var="employmentsSize" scope="request" />
							<td rowspan="${employmentsSize}">${employee.lastName}</td>
							<td rowspan="${employmentsSize}">${employee.firstName}</td>
							
							<td rowspan="${employmentsSize}">${employee.address.city.country.name}</td>
							<td rowspan="${employmentsSize}">${employee.address.city.name}</td>
							<td rowspan="${employmentsSize}">${employee.address.street}</td>
							<td rowspan="${employmentsSize}">${employee.address.house}</td>
							<td rowspan="${employmentsSize}">${employee.address.apartment}</td>	
							<td colspan="8" class="employmentCell">
								<c:forEach items="${employee.employments}" var="employment">
									<tr class="employment">
										<td class="employment">${employment.office.company.name}</td>
										<td class="employment">${employment.office.address.city.country.name}</td>
										<td class="employment">${employment.office.address.city.name}</td>
										<td class="employment">${employment.office.address.street}</td>
										<td class="employment">${employment.office.address.house}</td>
										<td class="employment">${employment.office.address.apartment}</td>
										<td class="employment">${employment.office.employeeCount}</td>
										<td class="employment">${employment.position.name}</td>
									</tr>
								</c:forEach>
							</td>
						</tr>					
					</c:forEach>	
				</table>
				<p:paging currentPageNumber="${param.page}" pagesRange="11"
							 entriesPerPage="${sessionScope.entriesPerPage}" entriesNumber="${requestScope.employeesNumber}"
							  pageAction="controller?command=employeeList" changeEntriesAction="controller?command=changeEntriesPerPage"/>
				<p><br/>Employees number: ${requestScope.employeesNumber}<br/>Execution time: ${requestScope.executionTime} ms</p>			
			</div>
			<div id="buffer">				
			</div>
		</div>
		<div id="footer">
			<jsp:include page="tiles/footer.jsp" />
		</div>
	</body>
</html>